{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Hierarchical Risk Parity - usage examples "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Abstract\n",
    "\n",
    "Hierarchical Risk Parity is a novel portfolio optimisation method developed by Marcos Lopez de Prado. The working of the\n",
    "algorithm can be broken down into 3 steps:\n",
    "\n",
    "1. Assets are segregated into clusters via hierarchical tree clustering.\n",
    "2. Based on these clusters, the covariance matrix of the returns is reorganized such that assets\n",
    "   within the same cluster are regrouped together.\n",
    "3. Finally, the weights are assigned to each cluster in a recursive manner. At each node, the weights are broken down\n",
    "   into the sub-cluster until all the individual assets are assigned a unique weight.\n",
    "\n",
    "Although, it is a simple algorithm, HRP has been found to be very stable as compared to its older counterparts.\n",
    "This is because, HRP does not involve taking inverse of the covariance matrix matrix which makes it robust to small changes\n",
    "in the covariances of the asset returns.\n",
    "\n",
    "For a detailed explanation of how HRP works, we have written an excellent `blog post <https://hudsonthames.org/an-introduction-to-the-hierarchical-risk-parity-algorithm/>`_ about it."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The objective of this notebook is to provide examples on how to use HRP in practice"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from mlfinlab.portfolio_optimization.hrp import HierarchicalRiskParity\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_weights(weights):\n",
    "    weights = weights.sort_values(by=0, ascending=False, axis=1)\n",
    "    plt.figure(figsize=(10, 5))\n",
    "    plt.bar(weights.columns, weights.values[0])\n",
    "    plt.xlabel('Tickers', fontsize=12)\n",
    "    plt.ylabel('Weights', fontsize=12)\n",
    "    plt.title('Portfolio Weights', fontsize=12)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EEM</th>\n",
       "      <th>EWG</th>\n",
       "      <th>TIP</th>\n",
       "      <th>EWJ</th>\n",
       "      <th>EFA</th>\n",
       "      <th>IEF</th>\n",
       "      <th>EWQ</th>\n",
       "      <th>EWU</th>\n",
       "      <th>XLB</th>\n",
       "      <th>XLE</th>\n",
       "      <th>...</th>\n",
       "      <th>XLU</th>\n",
       "      <th>EPP</th>\n",
       "      <th>FXI</th>\n",
       "      <th>VGK</th>\n",
       "      <th>VPL</th>\n",
       "      <th>SPY</th>\n",
       "      <th>TLT</th>\n",
       "      <th>BND</th>\n",
       "      <th>CSJ</th>\n",
       "      <th>DIA</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2008-01-02</th>\n",
       "      <td>49.273335</td>\n",
       "      <td>35.389999</td>\n",
       "      <td>106.639999</td>\n",
       "      <td>52.919998</td>\n",
       "      <td>78.220001</td>\n",
       "      <td>87.629997</td>\n",
       "      <td>37.939999</td>\n",
       "      <td>47.759998</td>\n",
       "      <td>41.299999</td>\n",
       "      <td>79.500000</td>\n",
       "      <td>...</td>\n",
       "      <td>42.090000</td>\n",
       "      <td>51.173328</td>\n",
       "      <td>55.983330</td>\n",
       "      <td>74.529999</td>\n",
       "      <td>67.309998</td>\n",
       "      <td>144.929993</td>\n",
       "      <td>94.379997</td>\n",
       "      <td>77.360001</td>\n",
       "      <td>101.400002</td>\n",
       "      <td>130.630005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-01-03</th>\n",
       "      <td>49.716667</td>\n",
       "      <td>35.290001</td>\n",
       "      <td>107.000000</td>\n",
       "      <td>53.119999</td>\n",
       "      <td>78.349998</td>\n",
       "      <td>87.809998</td>\n",
       "      <td>37.919998</td>\n",
       "      <td>48.060001</td>\n",
       "      <td>42.049999</td>\n",
       "      <td>80.440002</td>\n",
       "      <td>...</td>\n",
       "      <td>42.029999</td>\n",
       "      <td>51.293331</td>\n",
       "      <td>55.599998</td>\n",
       "      <td>74.800003</td>\n",
       "      <td>67.500000</td>\n",
       "      <td>144.860001</td>\n",
       "      <td>94.250000</td>\n",
       "      <td>77.459999</td>\n",
       "      <td>101.519997</td>\n",
       "      <td>130.740005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-01-04</th>\n",
       "      <td>48.223331</td>\n",
       "      <td>34.599998</td>\n",
       "      <td>106.970001</td>\n",
       "      <td>51.759998</td>\n",
       "      <td>76.570000</td>\n",
       "      <td>88.040001</td>\n",
       "      <td>36.990002</td>\n",
       "      <td>46.919998</td>\n",
       "      <td>40.779999</td>\n",
       "      <td>77.500000</td>\n",
       "      <td>...</td>\n",
       "      <td>42.349998</td>\n",
       "      <td>49.849998</td>\n",
       "      <td>54.536671</td>\n",
       "      <td>72.980003</td>\n",
       "      <td>65.769997</td>\n",
       "      <td>141.309998</td>\n",
       "      <td>94.269997</td>\n",
       "      <td>77.550003</td>\n",
       "      <td>101.650002</td>\n",
       "      <td>128.169998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-01-07</th>\n",
       "      <td>48.576668</td>\n",
       "      <td>34.630001</td>\n",
       "      <td>106.949997</td>\n",
       "      <td>51.439999</td>\n",
       "      <td>76.650002</td>\n",
       "      <td>88.199997</td>\n",
       "      <td>37.259998</td>\n",
       "      <td>47.060001</td>\n",
       "      <td>40.220001</td>\n",
       "      <td>77.199997</td>\n",
       "      <td>...</td>\n",
       "      <td>43.230000</td>\n",
       "      <td>50.416672</td>\n",
       "      <td>56.116669</td>\n",
       "      <td>72.949997</td>\n",
       "      <td>65.650002</td>\n",
       "      <td>141.190002</td>\n",
       "      <td>94.680000</td>\n",
       "      <td>77.570000</td>\n",
       "      <td>101.720001</td>\n",
       "      <td>128.059998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-01-08</th>\n",
       "      <td>48.200001</td>\n",
       "      <td>34.389999</td>\n",
       "      <td>107.029999</td>\n",
       "      <td>51.320000</td>\n",
       "      <td>76.220001</td>\n",
       "      <td>88.389999</td>\n",
       "      <td>36.970001</td>\n",
       "      <td>46.400002</td>\n",
       "      <td>39.599998</td>\n",
       "      <td>75.849998</td>\n",
       "      <td>...</td>\n",
       "      <td>43.240002</td>\n",
       "      <td>49.566669</td>\n",
       "      <td>55.326672</td>\n",
       "      <td>72.400002</td>\n",
       "      <td>65.360001</td>\n",
       "      <td>138.910004</td>\n",
       "      <td>94.570000</td>\n",
       "      <td>77.650002</td>\n",
       "      <td>101.739998</td>\n",
       "      <td>125.849998</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  EEM        EWG         TIP        EWJ        EFA        IEF  \\\n",
       "Date                                                                            \n",
       "2008-01-02  49.273335  35.389999  106.639999  52.919998  78.220001  87.629997   \n",
       "2008-01-03  49.716667  35.290001  107.000000  53.119999  78.349998  87.809998   \n",
       "2008-01-04  48.223331  34.599998  106.970001  51.759998  76.570000  88.040001   \n",
       "2008-01-07  48.576668  34.630001  106.949997  51.439999  76.650002  88.199997   \n",
       "2008-01-08  48.200001  34.389999  107.029999  51.320000  76.220001  88.389999   \n",
       "\n",
       "                  EWQ        EWU        XLB        XLE  ...        XLU  \\\n",
       "Date                                                    ...              \n",
       "2008-01-02  37.939999  47.759998  41.299999  79.500000  ...  42.090000   \n",
       "2008-01-03  37.919998  48.060001  42.049999  80.440002  ...  42.029999   \n",
       "2008-01-04  36.990002  46.919998  40.779999  77.500000  ...  42.349998   \n",
       "2008-01-07  37.259998  47.060001  40.220001  77.199997  ...  43.230000   \n",
       "2008-01-08  36.970001  46.400002  39.599998  75.849998  ...  43.240002   \n",
       "\n",
       "                  EPP        FXI        VGK        VPL         SPY        TLT  \\\n",
       "Date                                                                            \n",
       "2008-01-02  51.173328  55.983330  74.529999  67.309998  144.929993  94.379997   \n",
       "2008-01-03  51.293331  55.599998  74.800003  67.500000  144.860001  94.250000   \n",
       "2008-01-04  49.849998  54.536671  72.980003  65.769997  141.309998  94.269997   \n",
       "2008-01-07  50.416672  56.116669  72.949997  65.650002  141.190002  94.680000   \n",
       "2008-01-08  49.566669  55.326672  72.400002  65.360001  138.910004  94.570000   \n",
       "\n",
       "                  BND         CSJ         DIA  \n",
       "Date                                           \n",
       "2008-01-02  77.360001  101.400002  130.630005  \n",
       "2008-01-03  77.459999  101.519997  130.740005  \n",
       "2008-01-04  77.550003  101.650002  128.169998  \n",
       "2008-01-07  77.570000  101.720001  128.059998  \n",
       "2008-01-08  77.650002  101.739998  125.849998  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('../Sample-Data/stock_prices.csv')\n",
    "data.set_index('Date', inplace=True)\n",
    "data.index = pd.to_datetime(data.index)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In order to work, the Algo needs 2 important matrices:\n",
    "    * A covariance matrix for estimating the risk associated with each cluster\n",
    "    * A distance_matrix often derived directly from the covariance allowing to build our clusters\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Basic examples"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### First let's give the algo a dataframe or numpy array of raw prices with the corresponding names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmoAAAFQCAYAAAAP21IpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de7hkVXnn8e8PGEDFeKM1cm1EvIBGMC0mqIgRIg4KJIMBowYyKkFFY3QMJDCIRBzExJiMGGUUTeIFUSPpSCteERHQbuSijaINInQw2tIaJSLa8M4fex/YXV3ndJ3uU3U23d/P89Rz9l57rVXv2VW16621b6kqJEmS1D9bzHcAkiRJGs5ETZIkqadM1CRJknrKRE2SJKmnTNQkSZJ6ykRNkiSpp0zUJN3rJXlYkouT/CzJ36yn7gFJVnbmlyc5YOxBziDJLkluS7LlCHUXJqkkW00iNknzy0RN0tgluTHJ7W0y8oMk702y3Qb2dWqS9w8UHwv8CPi1qnrtbPqrqr2q6qJZxrBV+7/s2yl7QZtADZZ9a4QYbqqq7arqztnEMU1sw9aPpHspEzVJk/LcqtoOeCLwJODk2XYwwyjSrsC1NaEreFfVGuAy4Omd4v2Bbw0pu3gSMUnaNJmoSZqoqvp34JPA4wCS7JBkcZLVSVYkeelU3XZ06KNJ3p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gUe19R8J7Aic0mn26zQ3qN4VOBZ4LbCyfY6HAX8JeDFLSdMyUZMkeAHw2ar6UFX9qqpurapuorYDzQ3SP1JVJ8PdN+t+KfBnVbW6qn4GvAk4qtPuLuD1VXVHe1/EXwEPB3Ztn+dL3lJN0kxM1CQJdgaun2H5IcB9gHd2yhbQnKRwRbsr8yfAp9ryKauq6hed+bcAK4BPtzexPnFOope0yTJRkyS4mZnv5/f/aJKwJUnu15b9CLgd2KuqHtg+HtA9iYGB3ZpV9bOqem1VPQJ4LvCaJM+cu39D0qbGRE2S4APAgUn+IMlWSR6SZO+BOscD1wGfSHKfqrqLJoH72yQPBUiyY5JnTfckSZ6T5JHtbtOf0lwu5M7p6kuSiZqkzV5V3QT8d5qD/VfTnEjwhIE6RXNCwM3AvybZFjiBZlfm5Ul+CnwWePQMT7VHW+c24DLgHVV10Zz+M5I2KfE4VkmSpH5yRE2SJKmnTNQkSZJ6ykRNkiSpp0zUJEmSespETZIkqadM1CRJknrKRE2SJKmnTNQkSZJ6ykRNkiSpp/4/yr1GAsKQ+QQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "hrp = HierarchicalRiskParity()\n",
    "hrp.allocate(asset_prices=data, asset_names=data.columns)\n",
    "plot_weights(hrp.weights)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By default, the algo is asked to build a minimum variance portfolio being long on each asset\n",
    "The weight number k is just the proportion of your investment allocated to asset number k.\n",
    "\n",
    "Providing asset prices means the algo will compute the returns, a covariance matrix and the distance matrix."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "####  What if I want to give returns instead of price ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmoAAAFQCAYAAAAP21IpAAAABHNC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FjiBZlfm5Ul+CnwWePQMT7VHW+c24DLgHVV10Zz+M5I2KfE4VkmSpH5yRE2SJKmnTNQkSZJ6ykRNkiSpp0zUJEmSespETZIkqadM1CRJknrKRE2SJKmnTNQkSZJ6ykRNkiSpp/4/yr1GAsKQ+QQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "hrp = HierarchicalRiskParity()\n",
    "returns = data.pct_change()[1:]\n",
    "hrp.allocate(asset_returns=returns, asset_names=data.columns)\n",
    "plot_weights(hrp.weights)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As expected, we have found the exact same weights.\n",
    "\n",
    "Providing asset returns means the algo only need to compute a covariance matrix and the distance matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### But I have my own covariance matrix, already shrinked and proven to perform well out of sample, can I use it?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Of course Voilà"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmoAAAFQCAYAAAAP21IpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de7hkVXnn8e8PGEDFeKM1cm1EvIBGMC0mqIgRIg4KJIMBowYyKkFFY3QMJDCIRBzExJiMGGUUTeIFUSPpSCteERHQbuSijaINInQw2tIaJSLa8M4fex/YXV3ndJ3uU3U23d/P89Rz9l57rVXv2VW16621b6kqJEmS1D9bzHcAkiRJGs5ETZIkqadM1CRJknrKRE2SJKmnTNQkSZJ6ykRNkiSpp0zUJN3rJXlYkouT/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PUJEmSespETZIkqadM1CRJknrKRE3SZinJXyZ59wj13pdkncsNSNIkeNanpE1Skts6s/eluabX1DUJ/6Sq3jT5qCRpdkzUJG2Sqmq7qek0t3h6SVWtc8HTSUmyVa17U2pJmpG7PiVtlpKcmuT9nfmnJrk0yU+S3JzkmCFt7p/kC0n+Po1tkvx1kpuS/CDJO9Pc6okkB7RXqz8hyX8A702yfZJPtM+xOsmXprlDgiQBJmqSRJr7D34S+L/AApr7kl41UOchNPcK/XJVvaq9w8abgUe19R8J7Aic0mn26zQ3qN4VOBZ4LbCyfY6HAX8JeDFLSdMyUZMkeAHw2ar6UFX9qqpurapuorYDzQ3SP1JVJ8PdN+t+KfBnVbW6qn4GvAk4qtPuLuD1VXVHe1/EXwEPB3Ztn+dL3lJN0kxM1CQJdgaun2H5IcB9gHd2yhbQnKRwRbsr8yfAp9ryKauq6hed+bcAK4BPtzexPnFOope0yTJRkyS4mZnv5/f/aJKwJUnu15b9CLgd2KuqHtg+HtA9iYGB3ZpV9bOqem1VPQJ4LvCaJM+cu39D0qbGRE2S4APAgUn+IMlWSR6SZO+BOscD1wGfSHKfqrqLJoH72yQPBUiyY5JnTfckSZ6T5JHtbtOf0lwu5M7p6kuSiZqkzV5V3QT8d5qD/VfTnEjwhIE6RXNCwM3AvybZFjiBZlfm5Ul+CnwWePQMT7VHW+c24DLgHVV10Zz+M5I2KfE4VkmSpH5yRE2SJKmnTNQkSZJ6ykRNkiSpp0zUJEmSespETZIkqadM1CRJknrKRE2SJKmnTNQkSZJ6ykRNkiSpp/4/yr1GAsKQ+QQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "hrp = HierarchicalRiskParity()\n",
    "my_fav_cov_matrix = returns.cov()\n",
    "hrp.allocate(covariance_matrix=my_fav_cov_matrix, asset_names=data.columns)\n",
    "plot_weights(hrp.weights)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here the algo only has to compute the distance matrix from the covariance matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. More advanced examples"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### What if I want to use my prefered linkage method for the tree clustering part?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmoAAAFQCAYAAAAP21IpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de5wlZX3n8c8XWPCCUZTRyGUYQFBBI5gRE1TECAEXFZLFiFEDWZWgomt0E0hgEYkYxMSYrBhlI5rEC94imcgoXhER0BnkohDQGUAYMYqMRo2IDvz2j6qGmsPp7tM93adrZj7v1+u8+tRTTz31dJ1Lf/upW6oKSZIk9c8WC90BSZIkDWdQkyRJ6imDmiRJUk8Z1CRJknrKoCZJktRTBjVJkqSeMqhJ2ugleUSSi5L8JMlfT1P3wCRrOtPXJDlw3js5hSSLk/w0yZYj1F2SpJJsNY6+SVpYBjVJ8y7JTUnuaMPI95K8J8m2s2zr1CTvGyg+FvgB8CtV9bqZtFdVe1fVhTPsw1bt77Jfp+yFbYAaLLtuhD7cXFXbVtVdM+nHJH0btn0kbaQMapLG5TlVtS3wROBJwMkzbWCKUaRdgGtrTFfwrqp1wKXA0zvFBwDXDSm7aBx9krRpMqhJGquq+g7wSeBxAEl2SLIsydokq5K8bKJuOzr00STvS/Jj4Djgz4HntyNaVyV5L3A08Kdt2UFJtknytiS3to+3JdlmWH/a0b6D2ucjL0cTwA7oTD8NePOQsovatrdIcmKS1UluT/LhJA9t5623OzPJrp1duZ9NctaQUbIXJrk5yQ+Sn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sqturqhvUdqC58fpHqupkuOem2i8D/riq1lbVT4A3sf7N5O8GXl9Vd7b34fwl8Ehgl3Y9X/LWZ5KmYlCTJNgZWD3F/MOA+wPv7JQtojlJ4fJ2V+aPgE+15RNuq6qfd6bfAqwCPt3eNP3EOem9pE2WQU2S4Bamvv/g/6MJYcuTPLAt+wFwB7B3VT2kfTy4exIDA7s1q+onVfW6qtoNeA7w2iTPnLtfQ9KmxqAmSfB+4KAkv5dkqyQPS7LPQJ3jgeuBTyS5f1XdTRPg/ibJwwGS7JjkkMlWkuTZSR7V7jb9Mc3lQu6arL4kGdQkbfaq6mbgv9Mc7L+W5kSCJwzUKZoTAm4B/jXJ/YATaHZlXpbkx8BngUdPsao92jo/BS4F3lFVF87pLyNpkxKPY5UkSeonR9QkSZJ6yqAmSZLUUwY1SZKknjKoSZIk9ZRBTZIkqacMapIkST1lUJMkSeopg5okSVJPGdQkSZJ66v8DT+JhRXJ+w3kAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "hrp = HierarchicalRiskParity()\n",
    "my_fav_cov_matrix = returns.cov()\n",
    "hrp.allocate(covariance_matrix=my_fav_cov_matrix, asset_names=data.columns, linkage_method='ward')\n",
    "plot_weights(hrp.weights)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By default, HRP uses single linkage but any other technique implemented in scipy could do the job.\n",
    "The user can test various clustering method and see which one is the most robust for his particular task.\n",
    "https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html\n",
    "\n",
    "Note: The weights have changed a little bit compared to the single linkage method used in the Basic example section."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### How to provide my own distance matrix ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEU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T8d5qD/VfTnEjwhIE6RXNCwM3AvybZFjiBZlfm5Ul+CnwWePQMT7VHW+c24DLgHVV10Zz+M5I2KfE4VkmSpH5yRE2SJKmnTNQkSZJ6ykRNkiSpp0zUJEmSespETZIkqadM1CRJknrKRE2SJKmnTNQkSZJ6ykRNkiSpp/4/yr1GAsKQ+QQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    " def cov2corr(covariance):\n",
    "        \"\"\"\n",
    "        Calculate the correlations from asset returns covariance matrix.\n",
    "\n",
    "        :param covariance: (pd.Dataframe) asset returns covariances\n",
    "        :return: (pd.Dataframe) correlations between asset returns\n",
    "        \"\"\"\n",
    "        d_matrix = np.zeros_like(covariance)\n",
    "        diagnoal_sqrt = np.sqrt(np.diag(covariance))\n",
    "        np.fill_diagonal(d_matrix, diagnoal_sqrt)\n",
    "        d_inv = np.linalg.inv(d_matrix)\n",
    "        corr = np.dot(np.dot(d_inv, covariance), d_inv)\n",
    "        corr = pd.DataFrame(corr, index=covariance.columns, columns=covariance.columns)\n",
    "        return corr\n",
    "\n",
    "hrp = HierarchicalRiskParity()\n",
    "cov = returns.cov()\n",
    "corr = cov2corr(cov)\n",
    "distance = np.sqrt((1 - corr).round(5) / 2)\n",
    "hrp.allocate(distance_matrix=distance, covariance_matrix=cov, asset_names=data.columns)\n",
    "plot_weights(hrp.weights)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Yes that's exactly the same weights than the ones given by the Basic examples section because that's how HRP computes the distance matrix. Nonetheless, using the same parameter, you can provide your custom distance matrix.\n",
    "\n",
    "Remember to provide a covariance matrix (or prices, or returns) because the algo needs it to compute the intra cluster variance and then behave accordingly."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Is it possible to build a Long/Short portfolio ?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By using the side_weights parameter (pd.Series) with 1 for Buy and -1 for Sell and asset names as index.\n",
    "\n",
    "Note: The portfolio is dollar neutral 50% is assigned to buys and 50% for sells."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "EEM   -1\n",
       "EWG   -1\n",
       "TIP   -1\n",
       "EWJ   -1\n",
       "EFA    1\n",
       "IEF    1\n",
       "EWQ    1\n",
       "EWU    1\n",
       "XLB    1\n",
       "XLE    1\n",
       "XLF    1\n",
       "LQD    1\n",
       "XLK    1\n",
       "XLU    1\n",
       "EPP    1\n",
       "FXI    1\n",
       "VGK    1\n",
       "VPL    1\n",
       "SPY    1\n",
       "TLT    1\n",
       "BND    1\n",
       "CSJ    1\n",
       "DIA    1\n",
       "dtype: int64"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hrp = HierarchicalRiskParity()\n",
    "side_weights = pd.Series([1]*data.shape[1], index=data.columns)\n",
    "#Short the first 4 stocks\n",
    "side_weights.loc[data.columns[:4]] = -1\n",
    "hrp.allocate(asset_prices=data, asset_names=data.columns, side_weights=side_weights)\n",
    "side_weights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       " 1    19\n",
       "-1     4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "side_weights.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmwAAAFQCAYAAAACxSJuAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9y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4CaaAw4eN6VP0Rw4sBo4Lcm9gCNoNnF+J8kvgLOAPaa5qd3bPrcA5wEfqqpvjPSfkbRJifu5SpIkdZtr2CRJkjrOwCZJktRxBjZJkqSOM7BJkiR1nIFNkiSp4wxskiRJHWdgkyRJ6jgDmyRJUscZ2CRJkjru/wNQeBgzPjaIRwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_weights(hrp.weights)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Proportion $ allocated to short portf: -0.49999999999999994\n",
      "Proportion $ allocated to buy portf: 0.5\n"
     ]
    }
   ],
   "source": [
    "short_ptf = side_weights[side_weights==-1].index\n",
    "buy_ptf = side_weights[side_weights==1].index\n",
    "weights = hrp.weights.T\n",
    "print('Proportion $ allocated to short portf:', weights.loc[short_ptf].sum().item())\n",
    "print('Proportion $ allocated to buy portf:', weights.loc[buy_ptf].sum().item())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Conclusion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "HRP is a robust algo for minimum variance portfolio construction and for which the user will find a lot of freedom regarding the input parameters.\n",
    "\n",
    "You can also look at the HRP performance comparison with other portfolio construction techniques on the following notebook: https://github.com/hudson-and-thames/research/blob/master/Chapter16/Chapter16.ipynb"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
